package com.manage.web.controller;


import com.manage.model.po.User;
import com.manage.service.UserService;
import com.manage.web.bl.TestCreateTable;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户操作接口
 * @author duaiyu
 * @version V1.0
 * @date 2022/2/20
 * 来源：自研
 */
@Slf4j
@Controller
@RequestMapping(value = "/userController")
public class UserController {

    @Autowired
    UserService userService;

    @Resource
    JdbcTemplate jdbcTemplate;

    @ResponseBody
    @RequestMapping(value = "/queryUser", method = RequestMethod.GET)
    public List<User> queryUser(@RequestParam("id") String id) {
        log.info("查询用户入参：" + id);
        log.info("查询出的结果" + userService.queryUser(id));
        return userService.queryUser(id);
    }

    /**
     * 修改数据库表名
     */
    @ResponseBody
    @RequestMapping(value = "/alterTable", method = RequestMethod.GET)
    public void alterTable() {
        String oldTableName = "dateTable2023";
        String newTableName = "dateTable";
        String sql = TestCreateTable.alterTableName(oldTableName, newTableName);
        jdbcTemplate.execute(sql);
    }

    /**
     * 创建数据库表
     */
    @ResponseBody
    @RequestMapping(value = "/createTable", method = RequestMethod.GET)
    public void createTable() {
        String sql = TestCreateTable.createTableSQL();
        jdbcTemplate.execute(sql);
    }

}
